// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** downloadDataExcel POST /api/sql/download/data/excel */
export async function downloadDataExcelUsingPost(
  body: API.GenerateVO,
  options?: { [key: string]: any },
) {
  return request<any>('/api/sql/download/data/excel', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** generateBySchema POST /api/sql/generate/schema */
export async function generateBySchemaUsingPost(
  body: API.TableSchema,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseGenerateVO_>('/api/sql/generate/schema', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** getSchemaByAuto POST /api/sql/get/schema/auto */
export async function getSchemaByAutoUsingPost(
  body: API.GenerateByAutoRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseTableSchema_>('/api/sql/get/schema/auto', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** getSchemaByExcel POST /api/sql/get/schema/excel */
export async function getSchemaByExcelUsingPost(
  body: {},
  file?: File,
  options?: { [key: string]: any },
) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.BaseResponseTableSchema_>('/api/sql/get/schema/excel', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** getSchemaBySql POST /api/sql/get/schema/sql */
export async function getSchemaBySqlUsingPost(
  body: API.GenerateBySqlRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseTableSchema_>('/api/sql/get/schema/sql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}
